/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.MailConstants;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.Pair;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxManager.FetchMode;
/*     */ import com.zimbra.cs.session.WaitSetAccount;
/*     */ import com.zimbra.cs.session.WaitSetError;
/*     */ import com.zimbra.cs.session.WaitSetMgr;
/*     */ import com.zimbra.soap.DocumentHandler;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.ArrayList;
/*     */ import java.util.EnumSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateWaitSet
/*     */   extends MailDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  61 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  62 */     Element response = zsc.createElement(MailConstants.CREATE_WAIT_SET_RESPONSE);
/*  63 */     return staticHandle(this, request, context, response);
/*     */   }
/*     */   
/*     */   public static Element staticHandle(DocumentHandler handler, Element request, Map<String, Object> context, Element response) throws ServiceException {
/*  67 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  69 */     String defInterestStr = request.getAttribute("defTypes");
/*  70 */     Set<MailItem.Type> defaultInterests = WaitSetRequest.parseInterestStr(defInterestStr, EnumSet.noneOf(MailItem.Type.class));
/*     */     
/*  72 */     boolean adminAllowed = zsc.getAuthToken().isAdmin();
/*     */     
/*  74 */     boolean allAccts = request.getAttributeBool("allAccounts", false);
/*  75 */     if (allAccts) {
/*  76 */       WaitSetMgr.checkRightForAllAccounts(zsc);
/*     */     }
/*     */     
/*  79 */     List<WaitSetAccount> add = WaitSetRequest.parseAddUpdateAccounts(zsc, request.getOptionalElement("add"), defaultInterests);
/*     */     
/*     */ 
/*     */ 
/*  83 */     List<Mailbox> referencedMailboxes = new ArrayList();
/*  84 */     for (WaitSetAccount acct : add) {
/*     */       try {
/*  86 */         MailboxManager.FetchMode fetchMode = MailboxManager.FetchMode.AUTOCREATE;
/*  87 */         Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(acct.getAccountId(), fetchMode);
/*  88 */         referencedMailboxes.add(mbox);
/*     */       } catch (ServiceException e) {
/*  90 */         ZimbraLog.session.debug("Caught exception preloading mailbox for waitset", e);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*  95 */     Pair<String, List<WaitSetError>> result = WaitSetMgr.create(zsc.getRequestedAccountId(), adminAllowed, defaultInterests, allAccts, add);
/*  96 */     String wsId = (String)result.getFirst();
/*  97 */     List<WaitSetError> errors = (List)result.getSecond();
/*     */     
/*  99 */     response.addAttribute("waitSet", wsId);
/* 100 */     response.addAttribute("defTypes", WaitSetRequest.interestToStr(defaultInterests));
/* 101 */     response.addAttribute("seq", 0L);
/*     */     
/* 103 */     WaitSetRequest.encodeErrors(response, errors);
/*     */     
/* 105 */     return response;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/CreateWaitSet.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */